<template>
  <!--折线图-->
  <div
    :style="{width:width,height:height}"
  ></div>
</template>

<script>
  export default {
    name: 'LineChart',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '260px'
      },
      /**
       * @param:
       *    dataLine  --> 折线的数据
       *    dataY  --> Y轴的数据
       *    threshold --> 阈值
       * @date 2020/08/23
       * @author ZhuHongWei
       */
      chartData: {
        type: Object,
        default: () => {
        }
      }
    },
    data() {
      return {}
    },
    watch: {
      chartData: {
        deep: true,
        handler: function () {
          this.initChart()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart() {
        this.chart = this.$echarts.init(this.$el)
        this.chart.clear()
        let option = {
          title: {
            show: false,
            textStyle: {
              color: '#ffffff',
              fontStyle: 'normal',
              fontWeight: 'normal',
              fontSize: '18',
            }
          },
          grid: {
            left: '2%',
            right: '2%',
            bottom: '18%',
            top: '15%',
            containLabel: true
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'line',
              lineStyle: {color: '#FFFFFF',}
            },
            backgroundColor: '#333',
          },
          legend: {
            data: ['综合分数', '阈值'],
            textStyle: {
              color: '#B4B4B4'
            },
            top: '0%',
          },
          xAxis: [{
            boundaryGap: false,
            type: 'category',
            axisLabel: {
              show: true,
              interval: 0, // 横轴信息全部显示
              // rotate: 40, // x轴旋转
              textStyle: {
                color: "#FFFFFF",
                fontSize: 14
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            splitLine: {
              show: false,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisTick: {
              show: true
            },
            splitArea: {
              show: false
            },
            data: this.chartData.dataY
          }],
          yAxis: [{
            type: 'value',
            min: 40,
            max: 100,
            splitNumber: 7,
            name: '综合得分',
            nameTextStyle: {
              color: '#FFFFFF',
              fontSize: 12
            },
            splitLine: {
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(255,255,255,0.1)'
              }
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: "#ffffff",
                fontSize: 14
              }
            },
            axisTick: {
              show: false
            },
            splitArea: {
              show: false
            }
          }],
          series: [{
            name: '综合分数',
            type: 'line',
            symbolSize: 0,
            symbol: 'circle',
            smooth: true,
            itemStyle: {
              normal: {
                color: '#58A3F7',
                label: {
                  show: false,
                  textStyle: {
                    color: 'rgba(255,255,255,0.1)'
                  }
                },

              }
            },
            lineStyle: {
              normal: {
                color: 'rgba(24,106,209,1)' // 线条颜色
              }
            },
            label: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#ffffff'
              }
            },
            areaStyle: {
              normal: {
                color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: 'rgba(24,196,190,1)'
                  },
                  {
                    offset: 0.2,
                    color: 'rgba(24,196,190,1)'
                  },
                  {
                    offset: 1,
                    color: 'rgba(54,157,225,.2)'
                  }
                ], false),
                shadowColor: 'rgba(118,168,248, 0.9)' // 阴影颜色
              }
            },
            data: this.chartData.dataLine
          },
            {
              name:'阈值',
              type: 'line',
              markLine: {
                data: [{
                  name: '阈值',
                  yAxis: this.chartData.threshold, // 阈值
                  lineStyle: {
                    color: 'rgb(243, 123, 29)'
                  }
                }]
              }
            }
          ]
        }
        this.chart.setOption(option)
      }
    }
  }
</script>

<style scoped>
</style>
